<?php
namespace app\admin\controller;

class Login extends \think\Controller {
    public function index(){
        if(request()->isPost()) {
            $data = input();
//            $res = $this->validate($data,[
//                'captcha|验证码'=>'require|captcha'
//            ]);
//            if($res!=1) {
//                return returnJson(1,$res);
//            }
            $manager = db('manager')->where('mobile',$data['mobile'])->find();
            if(!$manager) {
                //return returnJson(1,'账号或密码错误');
            }
            $pw = md5($data['password'].config('SALT'));
            if($pw!=$manager['password']) {
                //return returnJson(1,'账号或密码错误');
            }
            session('admininfo',$manager);
            return returnJson(0,'登录成功','','/admin/index');
        }
        $this->view->engine->layout(false); 
        return $this->fetch();
    }
    public function quit () {
        session(null);
        $this->redirect('/admin/login');
    }
}
